package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 吴
 * @version V1.0
 * @Description  套餐信息
 * @Package com.itheima.controller
 * @date 2021/11/26 16:32
 */
@RestController
@RequestMapping("/setMeal")
public class SetmealController {

    @Reference
    private SetMealService setMealService;

    /**
     * 返回套餐列表
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll(){
        try {
            List<Setmeal> setMealAll = setMealService.findSetMealAll();
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS,setMealAll);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }

    /**
     * 根据套餐ID查询套餐详细信息（包括套餐基本信息、套餐包含的检查组、检查组包含的检查项）
     * @param setMealId
     * @return
     */
    @GetMapping("/findSetMealDetailById/{setMealId}")
    public Result findSetMealDetailById(@PathVariable("setMealId") Integer setMealId ){
        try {
            Setmeal info = setMealService.findCheckGroupInfoById(setMealId);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,info);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

    /**
     * 根据套餐ID查询套餐基本信息
     * @param setMealId
     * @return
     */
    @GetMapping("/findById/{setMealId}")
    public Result findById(@PathVariable("setMealId") Integer setMealId){
        try {
            Setmeal setmeal = setMealService.findSetmealById(setMealId);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

}
